home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / libraries / curses210.lha / src / waddstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-22  |  5.1 KB  |  147 lines

  1. /* -*-C-*-
  2.  *
  3.  *
  4.  * Filename : waddstr.c
  5.  *
  6.  * Author   : Simon J Raybould.    (sie@fulcrum.bt.co.uk).
  7.  *
  8.  * Date     : Friday 23rd August 1991.
  9.  *
  10.  * Desc     : Adds a string to the display buffer.
  11.  *
  12.  *
  13.  * THIS CODE IS NOT PUBLIC DOMAIN
  14.  * ==============================
  15.  * 
  16.  * This code is copyright Simon J Raybould 1991, all rights are reserved.
  17.  * All code, ideas, data structures and algorithms remain the property of the
  18.  * author. Neither the whole nor sections of this code may be used as part
  19.  * of other code without the authors consent. If you wish to use some of this
  20.  * code then please email me at (sie@fulcrum.bt.co.uk).
  21.  *
  22.  * This source is not public domain, so you do not have any right to alter it
  23.  * or sell it for personal gain. The source is provided purely for reference
  24.  * purposes. You may re-compile the source with any compiler you choose.
  25.  * You must not distribute altered copies without the authors consent. My
  26.  * intention is that the source will help people isolate any bugs much more
  27.  * effectivly.
  28.  *
  29.  * Disclaimer
  30.  * ==========
  31.  *
  32.  * No implication is made as to this code being fit for any purpose at all.
  33.  * I (the author) shall not be held responsible for any loss of data or damage 
  34.  * to property that may result from its use or misuse.
  35.  *
  36.  *
  37.  * Revision History
  38.  * ================
  39.  *
  40.  * $Log: waddstr.c,v $
  41.  * Revision 1.7  1993/05/17  23:33:10  sie
  42.  * Underscores added to names.
  43.  * Changes for version 2.10
  44.  *
  45.  * Revision 1.6  1992/06/21  01:12:54  sie
  46.  * Indentation.
  47.  *
  48.  * Revision 1.5  92/06/10  23:44:49  sie
  49.  * Added serial support.
  50.  * 
  51.  * Revision 1.4  92/01/25  23:55:34  sie
  52.  * Used define for TABSIZE rather than a hard coded 8.
  53.  * 
  54.  * Revision 1.3  91/12/28  22:45:23  sie
  55.  * changed attrs to UBYTE from short + some tidying up.
  56.  * 
  57.  * Revision 1.2  91/12/28  14:01:00  sie
  58.  * Removed WinStat.
  59.  * Renamed LineElement as lnel.
  60.  * 
  61.  * Revision 1.1  91/09/28  18:09:36  sie
  62.  * Initial revision
  63.  * 
  64.  *
  65.  */
  66.  
  67. static char *rcsid = "$Header: /SRC/lib/curses/src/RCS/waddstr.c,v 1.7 1993/05/17 23:33:10 sie Exp $";
  68.  
  69. #include "acurses.h"
  70.  
  71.  
  72. waddstr(WINDOW *WinPtr, char *Str)
  73. {
  74.   if(!*Str)
  75.     return OK;
  76.   
  77.   WinPtr->LnArry[WinPtr->_cury].Touched = TRUE;
  78.   WinPtr->LnArry[WinPtr->_cury].StartCol = min(WinPtr->LnArry[WinPtr->_cury].StartCol, WinPtr->_curx);
  79.   if(WinPtr->ParentWin) {
  80.     WinPtr->ParentWin->LnArry[WinPtr->_cury + WinPtr->_begy].Touched = TRUE;
  81.     WinPtr->ParentWin->LnArry[WinPtr->_cury + WinPtr->_begy].StartCol = min(WinPtr->ParentWin->LnArry[WinPtr->_cury + WinPtr->_begy].StartCol, WinPtr->_curx + WinPtr->_begx);
  82.   }
  83.   while(*Str) {
  84.     switch(*Str) {
  85.     case '\t':
  86.       do {
  87.     WinPtr->LnArry[WinPtr->_cury].Line[WinPtr->_curx] = ' ';
  88.     WinPtr->LnArry[WinPtr->_cury].ATTRS[WinPtr->_curx++] = WinPtr->_attrs;
  89.       } while(WinPtr->_curx % TABSIZE);
  90.       break;
  91.     case '\n':
  92.       WinPtr->LnArry[WinPtr->_cury].EndCol = max(WinPtr->LnArry[WinPtr->_cury].EndCol, WinPtr->_curx - 1);
  93.       wclrtoeol(WinPtr);
  94.       if(WinPtr->ParentWin)
  95.     WinPtr->ParentWin->LnArry[WinPtr->_cury+WinPtr->_begy].EndCol=max(WinPtr->ParentWin->LnArry[WinPtr->_cury+WinPtr->_begy].EndCol,WinPtr->_curx+WinPtr->_begx-1);
  96.       WinPtr->_curx=0;
  97.       WinPtr->_cury++;
  98.       if(WinPtr->_cury > WinPtr->ScrollBot) {
  99.     if(WinPtr->_scroll)
  100.       scroll(WinPtr);
  101.     WinPtr->_cury = WinPtr->ScrollBot;
  102.       }
  103.       if(*(Str + 1)) {  /* If there is more then touch this line too */
  104.     WinPtr->LnArry[WinPtr->_cury].Touched = TRUE;
  105.     WinPtr->LnArry[WinPtr->_cury].StartCol = min(WinPtr->LnArry[WinPtr->_cury].StartCol, WinPtr->_curx);
  106.     if(WinPtr->ParentWin) {
  107.       WinPtr->ParentWin->LnArry[WinPtr->_cury+WinPtr->_begy].Touched = TRUE;
  108.       WinPtr->ParentWin->LnArry[WinPtr->_cury+WinPtr->_begy].StartCol = min(WinPtr->ParentWin->LnArry[WinPtr->_cury+WinPtr->_begy].StartCol, WinPtr->_curx+WinPtr->_begx);
  109.     }
  110.       }
  111.       break;
  112.     default:
  113.       WinPtr->LnArry[WinPtr->_cury].Line[WinPtr->_curx] = *Str;
  114.       WinPtr->LnArry[WinPtr->_cury].ATTRS[WinPtr->_curx] = WinPtr->_attrs;
  115.       WinPtr->_curx++;
  116.       break;
  117.     } /* switch */
  118.     if(WinPtr->_curx > WinPtr->_maxx) {    /* If gone off end of line */
  119.       WinPtr->LnArry[WinPtr->_cury].EndCol = WinPtr->_maxx;
  120.       WinPtr->_curx = 0;
  121.       WinPtr->_cury++;
  122.       if(WinPtr->_scroll) {
  123.     if(WinPtr->_cury > WinPtr->ScrollBot) {
  124.       scroll(WinPtr);
  125.       WinPtr->_cury = WinPtr->ScrollBot;
  126.     }
  127.       }
  128.       if(WinPtr->_cury > WinPtr->_maxy)
  129.     WinPtr->_cury = WinPtr->_maxy;
  130.       if(*(Str + 1)) {  /* If there is more then touch this line too */
  131.     WinPtr->LnArry[WinPtr->_cury].Touched = TRUE;
  132.     WinPtr->LnArry[WinPtr->_cury].StartCol = WinPtr->_begx;
  133.     if(WinPtr->ParentWin) {
  134.       WinPtr->ParentWin->LnArry[WinPtr->_cury+WinPtr->_begy].Touched=TRUE;
  135.       WinPtr->ParentWin->LnArry[WinPtr->_cury+WinPtr->_begy].StartCol=
  136.         min(WinPtr->ParentWin->LnArry[WinPtr->_cury + WinPtr->_begy].StartCol, WinPtr->_begx);
  137.     }
  138.       }
  139.     } /* if gone off end of line */
  140.     Str++;
  141.   } /* while (*Str) */
  142.   WinPtr->LnArry[WinPtr->_cury].EndCol = max(WinPtr->LnArry[WinPtr->_cury].EndCol, WinPtr->_curx - 1);
  143.   if(WinPtr->ParentWin)
  144.     WinPtr->ParentWin->LnArry[WinPtr->_cury+WinPtr->_begy].EndCol = max(WinPtr->ParentWin->LnArry[WinPtr->_cury+WinPtr->_begy].EndCol, WinPtr->_curx+WinPtr->_begx-1);
  145.   return OK;
  146. }
  147.